#ifndef IAPMINIMAL_H
#define IAPMINIMAL_H

#include <QObject>
#include <QString>
#include <iapclient.h>
#include <QDeclarativeView>

class IAPminimal : public QObject
{
    Q_OBJECT
public:
    explicit IAPminimal(QDeclarativeView *parent);
    Q_PROPERTY(bool isPurchased READ isPurchased NOTIFY purchaseChanged)
    Q_PROPERTY(bool have2buy READ isHave2Buy WRITE setHave2Buy)
    bool isPurchased();

    inline bool isHave2Buy(){
        return is2buy;
    }

    inline void setHave2Buy(bool val){
        is2buy = val;
    }
    void initIAP();


signals:
    void productPurchaseComplete();
    void productPurchaseFailed();
    void purchaseChanged();

private slots:
    void productDataReceived(int requestId, QString status, IAPClient::ProductDataHash productData);
    void purchaseFlowFinished( int requestId );
    void purchaseCompleted( int requestId, QString status, QString purchaseTicket );
    void statusChanged (QDeclarativeView::Status status);
    void purchaseProduct();

private:
    void setUnlocked(QString *purchaseTicket);
    void saveTicket(QString *purchaseTicket);
    bool readTicket();
    QString getTicketUri();
    QString getTicketDir();
    bool checkDRM();

private:
    // data
    IAPClient *iap_client;
    bool      is2buy;
    enum{
        STATE_UNKNOWN,
        STATE_OK,
        STATE_FAILED
    } purchstate;
};

#endif // IAPMINIMAL_H
